package com.shujia.train

import com.alibaba.alink.common.MLEnvironmentFactory
import com.alibaba.alink.pipeline.PipelineModel
import org.apache.flink.api.java.operators.DataSource
import org.apache.flink.api.java.{DataSet, ExecutionEnvironment}
import org.apache.flink.table.api.Table
import org.apache.flink.table.api.bridge.java.BatchTableEnvironment
import org.apache.flink.types.Row

object TestModel {
  def main(args: Array[String]): Unit = {

    /**
      * 构建alink环境
      *
      */

    val env: ExecutionEnvironment = MLEnvironmentFactory.getDefault.getExecutionEnvironment
    val tableEnvironment: BatchTableEnvironment = MLEnvironmentFactory.getDefault.getBatchTableEnvironment

    val value: DataSource[String] = env.fromElements("新疆棉花真的好")

    val table: Table = tableEnvironment.fromDataSet(value, "text")

    /**
      * 加载模型
      *
      */

    val model: PipelineModel = PipelineModel.load("data/model")

    val table1: Table = model.transform(table)

    table1.printSchema()

    val reDS: DataSet[Row] = tableEnvironment.toDataSet(table1, classOf[Row])

    reDS.print()


  }
}
